package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Style;
import com.ruoyi.system.service.IStyleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 款式管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/system/style")
public class StyleController extends BaseController
{
    @Autowired
    private IStyleService styleService;

    /**
     * 查询款式管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:style:list')")
    @GetMapping("/list")
    public TableDataInfo list(Style style)
    {
        startPage();
        List<Style> list = styleService.selectStyleList(style);
        return getDataTable(list);
    }

    /**
     * 导出款式管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:style:export')")
    @Log(title = "款式管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Style style)
    {
        List<Style> list = styleService.selectStyleList(style);
        ExcelUtil<Style> util = new ExcelUtil<Style>(Style.class);
        util.exportExcel(response, list, "款式管理数据");
    }

    /**
     * 获取款式管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:style:query')")
    @GetMapping(value = "/{styleId}")
    public AjaxResult getInfo(@PathVariable("styleId") Long styleId)
    {
        return success(styleService.selectStyleByStyleId(styleId));
    }

    /**
     * 新增款式管理
     */
    @PreAuthorize("@ss.hasPermi('system:style:add')")
    @Log(title = "款式管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Style style)
    {
        return toAjax(styleService.insertStyle(style));
    }

    /**
     * 修改款式管理
     */
    @PreAuthorize("@ss.hasPermi('system:style:edit')")
    @Log(title = "款式管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Style style)
    {
        return toAjax(styleService.updateStyle(style));
    }

    /**
     * 删除款式管理
     */
    @PreAuthorize("@ss.hasPermi('system:style:remove')")
    @Log(title = "款式管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{styleIds}")
    public AjaxResult remove(@PathVariable Long[] styleIds)
    {
        return toAjax(styleService.deleteStyleByStyleIds(styleIds));
    }
}
